const state = {
  // snackbar: {
  //   show: true,
  //   timeout: -1,
  //   color: 'success',
  //   text: 'hello snackbar'
  // },
  snackbars: []
}

const mutations = {
  SET_SNACKBARS(state, snackbar) {
    state.snackbars = state.snackbars.concat(snackbar)
  },
  CLEAR_SNACKBARS(state) {
    state.snackbars = []
  }
}

const actions = {
  sendSnackbar({ commit }, snackbar) {
    const snackbarDefaultAttributes = {
      show: true,
      timeout: 1000,
      color: 'success',
      text: ''
    }
    snackbar = Object.assign(snackbarDefaultAttributes, snackbar)
    commit('SET_SNACKBARS', snackbar)
  },

  clearSnackbar({ commit }) {
    return new Promise(resolve => {
      commit('CLEAR_SNACKBARS')
      resolve()
    })
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
